package com.haoshui.controller;


import com.haoshui.domain.ResponseResult;
import com.haoshui.domain.dto.TagDto;
import com.haoshui.domain.entity.Tag;
import com.haoshui.service.TagService;
import com.haoshui.utils.BeanCopyUitls;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content")
@Api(description = "tag控制")
public class TagController {
    @Autowired
    private TagService tagService;


    /**
     * 获取tag分页查询
     * @param pageNum
     * @param pageSize
     * @param name
     * @param remark
     * @return
     */
    @GetMapping("/tag/list")
    public ResponseResult listTag(Integer pageNum, Integer pageSize, String name, String remark){

        return tagService.tagList(pageNum, pageSize, name, remark);
    }


    @GetMapping("/tag/listAllTag")
    public ResponseResult listAllTag(){
        return tagService.listAllTag();
    }



    /**
     * 添加tag
     * @param tagDto
     * @return
     */
    @PostMapping("/tag")
    public ResponseResult addTag(@RequestBody TagDto tagDto){
        return  tagService.addTag(tagDto);
    }

    /**
     * 删除tag
     * @param id
     * @return
     */
    @DeleteMapping("/tag/{id}")
    public ResponseResult deleteTag(@PathVariable("id") Long id){
        return tagService.deleteTag(id);
    }


    /**
     * 获取单个Tag的信息
     * @param id
     * @return
     */
    @GetMapping("/tag/{id}")
    public ResponseResult getTag(@PathVariable("id") Long id){
        return tagService.getTag(id);
    }

    /**
     * 修改Tag信息
     * @param tagDto
     * @return
     */
    @PutMapping("/tag")
    public ResponseResult updateTag(@RequestBody TagDto tagDto){
        //解封装
        Tag tag = BeanCopyUitls.copyBean(tagDto, Tag.class);
        return tagService.updateTag(tag);
    }

}
